package com.farmpost.server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmpost.server.pojo.Rent;
import com.farmpost.server.pojo.RespBean;
import com.farmpost.server.service.IRentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 租房表 前端控制器
 * </p>
 *
 * @author king
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/rent")
public class RentController {

    @Autowired
    private IRentService iRentService;

    @ApiOperation(value = "查询所有租房信息")
    @GetMapping("/rents")
    public List<Rent> getAllRent(@RequestParam Integer currentPage) {
        Page<Rent> rentPage = new Page<>(currentPage, 20, false);
        return iRentService.getAllRent(rentPage);
    }

    @ApiOperation(value = "发布租房/出租信息")
    @PutMapping("/insertRent")
    public RespBean insertRent(@RequestBody Rent rent) {
        return iRentService.insertRent(rent);
    }

    @ApiOperation(value = "查询出租信息")
    @GetMapping("/getRentByLease")
    public List<Rent> getRentByLease() {
        return iRentService.getRentByLease();
    }

    @ApiOperation(value = "查询租房信息")
    @GetMapping("/getRentByRent")
    public List<Rent> getRentByRent() {
        return iRentService.getRentByRent();
    }

    @ApiOperation(value = "修改租房信息")
    @PostMapping("/updateRent")
    public RespBean updateRent(@RequestBody Rent rent) {
        return iRentService.updateRent(rent);
    }

    @ApiOperation(value = "根据id删除租房信息")
    @DeleteMapping("/deleteRent")
    public RespBean deleteRent(@RequestParam Integer id) {
        return iRentService.deleteRent(id);
    }
}
